package homework08;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class homework003 {
	public static void main(String[] args) throws Exception {
		BufferedReader buf=null;
		String strNum;	
		buf=new BufferedReader(new FileReader("sort.txt"));
		String str=null;
		Map map=new HashMap();
		List<String> list=new ArrayList<String>();
		while((str=buf.readLine())!=null){
			strNum=str.substring(0);
			list.add(strNum);
			map.put(strNum, str);
		}
		Collections.sort(list);
		List<String> lastList=new ArrayList<>();
		for (int i=0;i<list.size();i++){
			lastList.add(map.get(list.get(i)).toString());
		}
		BufferedWriter bufWriter=new BufferedWriter(new FileWriter("sort.txt"));
		for (String s:lastList){
			bufWriter.write(s);
			System.out.println(s);
		}
		bufWriter.close();
		
	}
}
